package appx.craft.droid.uc;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import appx.craft.droid.R;

/**
 * This class used for to show pop up for save item in  horizontal list view  
 *
 */
public class PopUpSaveItem extends Dialog implements OnClickListener{

	private EditText medit_textView_item;
	private Button btn_Save_item;
	private ImageView imageView_Close;
	private ItemSaveListener mSaveListener;
	private Context mContext;
	public PopUpSaveItem(Context context) {
		super(context,R.style.CustomDialog);
		mSaveListener = (ItemSaveListener)context;
		mContext = context;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_save_item);
		
		medit_textView_item = (EditText)findViewById(R.id.edit_textView_item);
		btn_Save_item = (Button)findViewById(R.id.btn_Save_item);
		btn_Save_item.setOnClickListener(this);
		imageView_Close = (ImageView)findViewById(R.id.imageView_Close);
		imageView_Close.setOnClickListener(this);
		
	}

	@Override
	public void onClick(View v) {
		if(v.getId() == R.id.imageView_Close){
			dismiss();
		}else if(v.getId() == R.id.btn_Save_item){
			if(medit_textView_item.getText().toString().length() > 0 && medit_textView_item != null){
				mSaveListener.onItemSaveClick(medit_textView_item.getText().toString());
				InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
				imm.hideSoftInputFromWindow(medit_textView_item.getWindowToken(), 0);
				dismiss();
			}else{
				Toast.makeText(getContext(),"Please enter item !!", Toast.LENGTH_LONG).show();
			}
			
		}
	}
}
